<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>SpringBoot集成Thymeleaf模板引擎</title>
</head>
<body>
<h1>Thymeleaf语法讲解</h1>
<hr>
<h2>变量的输出</h2>
<h3>(1)th:text:在页面中输出值或内容</h3>
<p th:text="黑龙江农垦职业学院"></p>
<p th:text="${msg}"></p>
<h3>(2)th:value:可以将一个值放入input标签的value中</h3>
<input type="text" th:value="${msg}">
<h3>
    (3)字符串操作:Thymeleaf提供了一些内置对象,内置对象可以直接在模板中使用
    这些对象是#引用,大部分的内置对象都是以s结尾,如strings,numbers,dates
</h3>
<p th:text="${#strings.isEmpty(msg)}"></p>
<p th:text="${#strings.contains(msg,'T')}"></p>
<p th:text="${#strings.startsWith(msg,'T')}"></p>
<p th:text="${#strings.startsWith(msg,'f')}"></p>
<p th:text="${#strings.length(msg)}"></p>
<p th:text='${#strings.indexOf(msg,"me")}'></p>
<p th:text="${#strings.substring(msg,2)}"></p>
<p th:text="${#strings.substring(msg,2,5)}"></p>
<p th:text="${#strings.toUpperCase(msg)}"></p>
<p th:text="${#strings.toLowerCase(msg)}"></p>
<h3>(4)日期格式化处理</h3>
<p th:text="${date}"></p>
<p th:text="${#dates.format(date)}"></p>
<p th:text="${#dates.format(date,'yyyy/MM/dd')}"></p>
<p th:text="${#dates.format(date,'yyyy')}"></p>
<hr>
<h2>4.th:object的使用:*{}选择变量表达式</h2>
<div th:object="${user}">
    <p th:text="*{username}"></p>
    <p th:text="*{usersex}"></p>
    <p th:text="*{userage}"></p>
</div>
<h2>5.th:inline内联的使用</h2>
<p th:text="黑龙江农垦职业学院">软件技术专业</p>
<p th:inline="text">控制器传来的消息:[[${msg}]]</p>
<h2>6.条件判断:th:if</h2>
<div>
    <span th:if="${sex}=='男'">男</span>
    <span th:if="${sex}=='女'">女</span>
</div>
<hr>
<h2>多分支:th:switch</h2>
<div th:switch="${id}">
    <span th:case="1">1</span>
    <span th:case="2">2</span>
    <span th:case="3">3</span>
    <span th:case="*">*</span>
</div>
<hr>
<h2>迭代循环:list,th:each</h2>
<table border="1" width="100%">
    <tr>
        <th>UserName</th>
        <th>UserSex</th>
        <th>UserAge</th></tr>
    <tr th:each="user:${userList}">
        <th th:text="${user.username}"></th>
        <th th:text="${user.usersex}"></th>
        <th th:text="${user.userage}"></th>
    </tr>
</table>
<hr>
<h2>th:each状态变量</h2>
<table border="1" width="100%">
    <tr>
        <th>Index</th>
        <th>Count</th>
        <th>Size</th>
        <th>Odd</th>
        <th>Even</th>
        <th>First</th>
        <th>Last</th>
        <th>UserName</th>
        <th>UserSex</th>
        <th>UserAge</th>
    </tr>
    <tr th:each="user,suibian:${userList}">
        <th th:text="${suibian.index}"></th>
        <th th:text="${suibian.count}"></th>
        <th th:text="${suibian.size}"></th>
        <th th:text="${suibian.odd}"></th>
        <th th:text="${suibian.even}"></th>
        <th th:text="${suibian.first}"></th>
        <th th:text="${suibian.last}"></th>
        <th th:text="${user.username}"></th>
        <th th:text="${user.usersex}"></th>
        <th th:text="${user.userage}"></th>
    </tr>
</table>
<hr>
<h2>10.th:each迭代Map</h2>
<table border="1" width="100%">
    <tr>
        <th>Value</th>
    </tr>
    <tr th:each="map:${userMap}">
        <td th:text="${map}"></td>
    </tr>
</table>
<hr>
<h2>从Map中进行取值</h2>
<table border="1" width="100%">
    <tr>
        <th>Key</th>
        <th>UserName</th>
        <th>UserSex</th>
        <th>UserAge</th>
    </tr>
    <tr th:each="map:${userMap}">
        <td th:text="${map.key}"></td>
        <td th:text="${map.value.username}"></td>
        <td th:text="${map.value.usersex}"></td>
        <td th:text="${map.value.userage}"></td>
    </tr>
</table>
<h2>操作域对象:request\session\application</h2>
<p>HttpServletRequest: <span th:text="${#request.getAttribute('req')}"></span></p>
<p>HttpServletRequest: <span th:text="${#httpServletRequest.getAttribute('req')}"></span></p>
<p>HttpSession:<span th:text="${session.seq}"></span></p>
<p>HttpSession:<span th:text="${#httpSession.getAttribute('seq')}"></span></p>
<p>Application:<span th:text="${#request.getAttribute('app')}"></span></p>
<p>Application:<span th:text="${#servletContext.getAttribute('app')}"></span></p>
<hr>
<h2>URL表达式</h2>
<a th:href="@{http://www.baidu.com}">百度一下</a>
<a th:href="@{http://www.nkzy.org.cn}">黑龙江农垦职业学院</a>
<a th:href="@{/show2}">打开show2</a>
<hr>
<h2>在URL传递参数</h2>
<a th:href="@{/show2?id=1&name=张三李四}">打开show2</a><br>
<a th:href="@{/show2(id=2,name=王五赵六)}">打开show2</a>
<a th:href="@{/show2(id=${id},name=${name})}">打开show2</a>\
<a th:href="@{'/show2?id='+${id}+'&name='+${name}}">打开show2</a>
<hr>
<h2>restful格式url传递参数</h2>
<a th:href="@{/show3/{id}(id=1)}">restful格式传参方式一</a>
<a th:href="@{/show4/{id}/{name}(id=1,name=admin100)}">restful格式传参方式二</a>
<a th:href="@{/show5/{id}/(id=1,name=admin100)}">restful格式传参方式三</a>
<a th:href="@{/show5/{id}/(id=${id},name=${name})}">restful格式传参方式四</a>
</body>
</html>